package com.example.lib.c1;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

public class Main1 {
    public static void main(String[] args) {
        /*虚拟机线程管理的接口*/
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        /*取得线程信息*/
        ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(false, false);
        for (ThreadInfo info : threadInfos) {
            System.out.println("[" + info.getThreadId() + "]" + " " + info.getThreadName());
        }
        /* 上面打印如下，有5个线程， 可以看出java默认就是多线程
        [5] Attach Listener
        [4] Signal Dispatcher
        [3] Finalizer
        [2] Reference Handler
        [1] main
        当有资源回收的时候，jvm才会启动GC
         */
    }
}
